<%@ page import="java.util.*" contentType="text/html"%>
<%@ page import="model.Measurement" contentType="text/html"%>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript"> 
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
    	  
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Year');
        data.addColumn('number', 'lamp');          
        
        <% 
        int dagen = 1;
        if(request.getAttribute("dagenVerschil") == null){
        } else{
        	  dagen = (Integer)request.getAttribute("dagenVerschil");
        }
      	  if(dagen != -1 && request.getAttribute("dagenLijst") != null && request.getAttribute("light") != null){
		  			int[] urenWaardes = (int[])request.getAttribute("dagenLijst");
		  			int[][] waardes = (int[][])request.getAttribute("light");
		  		    dagen = (Integer)request.getAttribute("dagenVerschil");
		  		    
		  		    for(int x = 0; x < dagen; x++){
    	 	 			for(int i = 0; i<urenWaardes.length; i++){	%>
    						var date = '<%= urenWaardes[i] %>';
    	 					var getal = <%= waardes[x][i]%>;
    						data.addRows([[ date , getal]]  );
    	 	 			
    	 	 	<%  }   } 
    	 	  }else if(request.getAttribute("dagenLijst") == null &&  !request.getAttribute("eersteKeer").equals("eersteKeer") && (Integer)request.getAttribute("keerGedaan") <1 ){
    	 		  request.setAttribute("keerGedaan", (Integer)request.getAttribute("keerGedaan") +1 ); %>
    	 		 alert("kan niet meer dan 28 dagen verschil zijn"); <%
    	 	  } else if( !request.getAttribute("eersteKeer").equals("eersteKeer") && (Integer)request.getAttribute("keerGedaan") <1 ){
          	 	  request.setAttribute("keerGedaan", (Integer)request.getAttribute("keerGedaan") +1 ); %>
						alert("geen geldige invoer");
          	   <% } %>

    	  var ac = new google.visualization.AreaChart(document.getElementById('chart_div'));
          ac.draw(data, {
            isStacked: true,
            width: 600,
            height: 400, 
            vAxis: {title: 'Lamp', minValue: 0, maxValue: 2},
            hAxis: {title: "Uren"}
          });
      }
    </script>